//
//  FDBaseViewVC.m
//  FamousDoctorOnline
//
//  Created by 刘胤辰 on 16/7/6.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#define viewHeight self.view.frame.size.width*0.1

#import "FDOperationVC.h"
#import "FDBaseViewVC.h"
#import <Masonry.h>
#import "YCViewModel.h"
#import "FDTableVIewVC.h"
#import "FDCellModel.h"
#import "FDDiseaseSubdivideViewController.h"
#import "FDAttentionController.h"
#import "MJExtension.h"
#import <Masonry.h>

@interface FDBaseViewVC ()

@property(nonatomic,strong)UIButton *btn2;
@property(nonatomic,strong)UIButton *btn3;
@property(nonatomic,strong)UILabel *label1;
@property(nonatomic,strong)UILabel *label2;
@property(nonatomic,strong)UILabel *label3;
@property(nonatomic,strong)UIButton *SwithchBtn1;
@property(nonatomic,strong)UIButton *SwithchBtn2;
@property(nonatomic,strong)UIButton *SwithchBtn3;
@property(nonatomic,strong)UIButton *SwithchBtn4;
@property(nonatomic,strong)UILabel *leftLab1;
@property(nonatomic,strong)UILabel *leftLab2;

@end

@implementation FDBaseViewVC

-(UIButton *)btn2{
    
    if (_btn2==nil) {
        
        _btn2=[[UIButton alloc]init];
    }
    return _btn2;
}

-(void)setLabelStr3:(NSString *)labelStr3{
    
    _labelStr3=labelStr3;
    
    self.label3.text=labelStr3;
    //数据存储在本地
    [WZHUserDefaults WZHSaveObject:labelStr3 forKey:[NSString stringWithFormat:@"%@labelStr3",self.title]];
    self.label3.textColor=[UIColor blackColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[[UIColor alloc]initWithRed:235.0/255.0 green:235.0/255.0 blue:241.0/255.0 alpha:1.0];
    
    [self setUI];

}

//加载UI
-(void)setUI{
    
    //添加用户信息lable
    UILabel *label1=[[UILabel alloc]init];

    label1.text=@"用户信息：王二狗1111";
    if (ten==10) {
        
        label1.font=[UIFont systemFontOfSize:16];
    }else{
        label1.font=[UIFont systemFontOfSize:15];
    }
    
    //添加疾病类型label
    UILabel *label2=[[UILabel alloc]init];
    label2.text=[NSString stringWithFormat:@"疾病类型：%@",self.titleText];
    if (ten==10) {
        
        label2.font=[UIFont systemFontOfSize:16];
    }else{
        label2.font=[UIFont systemFontOfSize:15];
    }
    
    //添加第一个view
    UIButton *btn1=[[UIButton alloc]init];
    [self loadBtnBaseView1:label2 xMargin:ten i:0 btn:btn1];
    btn1.tag=1;
    
    //添加第二个View
    [self loadBtnBaseView2:label2 xMargin:ten i:1 btn:self.btn2];
    self.btn2.tag=2;
    
    //添加第三个View
    UIView *View1=[[UIView alloc]init];
    [self loadBtnBaseView1:label2 xMargin:ten i:2 view:View1];
    
    //添加第四个View
    UIView *View2=[[UIView alloc]init];
    [self loadBtnBaseView2:label2 xMargin:ten i:3 view:View2];
    
    //添加第五（隐藏）个view
    self.btn3=[[UIButton alloc]init];
    [self loadBtnBaseView3:label2 xMargin:ten i:4 btn:self.btn3];
    self.btn3.hidden=YES;
    self.btn3.tag=3;
    
    //加载本地数据的时候判断第五个view是否显示
    BOOL selectedtd= [WZHUserDefaults WZHBoolForKey:[NSString stringWithFormat:@"%@SwithchBtn4",self.title]];
    
    if (selectedtd) {
        
        self.btn3.hidden=NO;
    }
    
    //添加就医申请按钮
    YCButton *btn=[YCButton initWithFrame:CGRectZero Title:@"就医申请" titleState:UIControlStateNormal ImageName:@"nav" HighlightedImage:nil addTarget:self action:@selector(clickApplyFor) forControlEvents:UIControlEventTouchUpInside];
    
    //创建医生人数label
    UILabel *label=[[UILabel alloc]init];
    label.font=[UIFont systemFontOfSize:16];
    label.text=@"为您匹配到：42位医生";
    
    //添加下部的图片
    UIImageView *imgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];

    [self.view addSubview:imgView];
    [self.view addSubview:label];
    [self.view addSubview:btn];
    [self.view addSubview:label1];
    [self.view addSubview:label2];
    
    //设置约束
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_offset(ten);
        make.top.mas_offset(self.navigationController.navigationBar.frame.size.height+ten*2+ten);
    }];
    
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_offset(ten);
        make.top.mas_equalTo(label1.mas_bottom).offset(ten/2);
    }];
    
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_offset(ten);
        make.right.mas_offset(-ten);
        make.top.mas_equalTo(label2.mas_bottom).offset(ten);
        make.height.mas_equalTo(viewHeight);
    }];
    
    [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_offset(ten);
        make.right.mas_offset(-ten);
        make.top.mas_equalTo(btn1.mas_bottom).offset(ten);
        make.height.mas_equalTo(viewHeight);
    }];
    
    [View1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_offset(ten);
        make.right.mas_offset(-ten);
        make.top.mas_equalTo(self.btn2.mas_bottom).offset(ten);
        make.height.mas_equalTo(viewHeight);
    }];
    
    [View2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_offset(ten);
        make.right.mas_offset(-ten);
        make.top.mas_equalTo(View1.mas_bottom).offset(ten);
        make.height.mas_equalTo(viewHeight);
    }];
    
    [self.btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_offset(ten);
        make.right.mas_offset(-ten);
        make.top.mas_equalTo(View2.mas_bottom).offset(ten);
        make.height.mas_equalTo(viewHeight);
    }];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_offset(-2*ten);
        make.left.mas_offset(ten);
        make.right.mas_offset(-ten);
        make.height.mas_equalTo(viewHeight);
    }];
    
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(btn.mas_top).offset(-4*ten);
        make.centerX.mas_offset(0);
        make.width.mas_equalTo(7*ten);
        make.height.mas_equalTo(7*ten);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(imgView.mas_top).offset(-2*ten);
        make.centerX.mas_offset(0);
    }];
    
}

//MARK:设置UI的界面
-(void)loadBtnBaseView1:(UILabel *)label2 xMargin:(CGFloat)xMargin  i:(CGFloat)i btn:(UIButton *)btn1{

    btn1.backgroundColor=[UIColor whiteColor];
    
    //创建左边的label
    self.label1=[[UILabel alloc]init];
    self.label1.font=[UIFont systemFontOfSize:15];
    [btn1 addSubview:self.label1];
    
    //创建右边的线
    UIView *line=[[UIView alloc]init];
    [btn1 addSubview:line];
    line.backgroundColor=[[UIColor alloc]initWithWhite:0.5 alpha:0.5];
    [btn1 addTarget:self action:@selector(changeVC:) forControlEvents:UIControlEventTouchUpInside];
    
    //创建右边绿色箭头
    UIImageView *image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
    
    [btn1 addSubview:image];
    
    [self.view addSubview:btn1];
    
    //从本地取出数据
    NSString *showText= [WZHUserDefaults WZHObjectForKey:[NSString stringWithFormat:@"%@showText",self.title]];
    if (showText.length) {
        
        self.label1.text=showText;
        self.label1.textColor=[UIColor blackColor];
        
    }else{
        self.label1.text=@"请选择疾病细分";
        self.label1.textColor=[UIColor lightGrayColor];
    }
    
    //设置约束
    [self.label1 mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.left.mas_offset(ten);
        make.centerY.mas_offset(0);
    }];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_offset(-1.7*ten);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(0.8*ten);
        make.height.mas_equalTo(ten);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(image.mas_left).offset(-ten);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(ten/8);
        make.height.mas_equalTo(viewHeight/1.8);
    }];

}

//第二个view
-(void)loadBtnBaseView2:(UILabel *)label2 xMargin:(CGFloat)xMargin  i:(CGFloat)i btn:(UIButton *)btn1{
    
    btn1.backgroundColor=[UIColor whiteColor];
    
    //创建左边的label
    self.label2=[[UILabel alloc]init];
    self.label2.font=[UIFont systemFontOfSize:15];
    [btn1 addSubview:self.label2];
    
    //创建右边的线
    UIView *line=[[UIView alloc]init];
    [btn1 addSubview:line];
    line.backgroundColor=[[UIColor alloc]initWithWhite:0.5 alpha:0.5];
    [btn1 addTarget:self action:@selector(changeVC:) forControlEvents:UIControlEventTouchUpInside];
    
    //创建右边绿色箭头
    UIImageView *image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
    
    [btn1 addSubview:image];
    
    [self.view addSubview:btn1];
    
    //加载本地数据并进行赋值
    [self getHomeDataAndSetData];
    
    //设置约束
    [self.label2 mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.left.mas_offset(ten);
        make.centerY.mas_offset(0);
        make.width.mas_offset(self.view.frame.size.width-8*ten);
    }];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_offset(-1.7*ten);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(0.8*ten);
        make.height.mas_equalTo(ten);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(image.mas_left).offset(-ten);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(ten/8);
        make.height.mas_equalTo(viewHeight/1.8);
    }];
    
}

//第三个view
-(void)loadBtnBaseView1:(UILabel *)label2 xMargin:(CGFloat)xMargin  i:(CGFloat)i view:(UIView *)view {
    
    view.frame=CGRectMake(xMargin, CGRectGetMaxY(label2.frame)+10+(viewHeight +15)*i, self.view.frame.size.width-xMargin *2, viewHeight);
    view.backgroundColor=[UIColor whiteColor];
    //创建左边的label
    self.leftLab1=[[UILabel alloc]init];
    self.leftLab1.font=[UIFont systemFontOfSize:15];
    
    //创建右边的两个view
    self.SwithchBtn1=[YCButton initWithFrame:CGRectZero Title:nil titleState:0 ImageName:nil HighlightedImage:nil addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
 
    [self.SwithchBtn1 setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
    
    [self.SwithchBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.SwithchBtn1 setTitle:@"症状疑似" forState:UIControlStateNormal];
    
    self.SwithchBtn1.imageEdgeInsets=UIEdgeInsetsMake(0, 0, 0, self.SwithchBtn1.titleLabel.frame.size.width+0.5*ten);

    [self.SwithchBtn1 setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
    
    self.SwithchBtn1.titleLabel.font=[UIFont systemFontOfSize:15];
    
    self.SwithchBtn2=[YCButton initWithFrame:CGRectZero Title:nil titleState:0 ImageName:nil HighlightedImage:nil addTarget:self action:@selector(click2:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.SwithchBtn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.SwithchBtn2 setTitle:@"已确诊" forState:UIControlStateNormal];
    
    self.SwithchBtn2.imageEdgeInsets=UIEdgeInsetsMake(0, 0,0, self.SwithchBtn1.titleLabel.frame.size.width+0.5*ten);
    self.SwithchBtn2.titleLabel.font=[UIFont systemFontOfSize:15];
    
    [self.SwithchBtn2 setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
    [self.SwithchBtn2 setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
    
    //加载本地数据
    BOOL selectedBtn2= [WZHUserDefaults WZHBoolForKey:[NSString stringWithFormat:@"%@SwithchBtn2",self.title]];
    self.SwithchBtn2.selected=selectedBtn2;
    BOOL selectedBtn1= [WZHUserDefaults WZHBoolForKey:[NSString stringWithFormat:@"%@SwithchBtn1",self.title]];
    self.SwithchBtn1.selected=selectedBtn1;
    
    [view addSubview:self.SwithchBtn1];
    [view addSubview:self.SwithchBtn2];
    [view addSubview:self.leftLab1];
    [self.view addSubview:view];
    
    NSString *left1= [WZHUserDefaults WZHObjectForKey:[NSString stringWithFormat:@"%@left1",self.title]];
    
    if (left1) {
        
        self.leftLab1.text=left1;
        self.leftLab1.textColor=[UIColor blackColor];
    }else{
        
        self.leftLab1.text=@"是否确诊";
        self.leftLab1.textColor=[UIColor lightGrayColor];
    }
    
    [self.leftLab1 mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.left.mas_offset(ten);
        make.centerY.mas_offset(0);
    }];
    
    [self.SwithchBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_offset(ten*1.2);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(10*ten);
        make.height.mas_equalTo(3*ten);
    }];
    
    [self.SwithchBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_offset(self.view.frame.size.width*0.3);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(9*ten);
        make.height.mas_equalTo(3*ten);
    }];
}

//第四个view
-(void)loadBtnBaseView2:(UILabel *)label2 xMargin:(CGFloat)xMargin  i:(CGFloat)i view:(UIView *)view {

    view.backgroundColor=[UIColor whiteColor];
    //创建左边的label
    self.leftLab2=[[UILabel alloc]init];
    self.leftLab2.font=[UIFont systemFontOfSize:15];
    
    //创建右边的两个view
    self.SwithchBtn3=[YCButton initWithFrame:CGRectZero Title:nil titleState:0 ImageName:nil HighlightedImage:nil addTarget:self action:@selector(click3:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.SwithchBtn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.SwithchBtn3 setTitle:@"未接受过" forState:UIControlStateNormal];
    
    self.SwithchBtn3.imageEdgeInsets=UIEdgeInsetsMake(0, 0, 0, self.SwithchBtn1.titleLabel.frame.size.width+0.5*ten);
    self.SwithchBtn3.titleLabel.font=[UIFont systemFontOfSize:15];
    
    [self.SwithchBtn3 setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
    [self.SwithchBtn3 setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
    
    //加载本地数据
    BOOL selected= [WZHUserDefaults WZHBoolForKey:[NSString stringWithFormat:@"%@SwithchBtn3",self.title]];
    self.SwithchBtn3.selected=selected;
    
    self.SwithchBtn4=[YCButton initWithFrame:CGRectZero Title:nil titleState:0 ImageName:nil HighlightedImage:nil addTarget:self action:@selector(click4:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.SwithchBtn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.SwithchBtn4 setTitle:@"接受过" forState:UIControlStateNormal];
    
    self.SwithchBtn4.imageEdgeInsets=UIEdgeInsetsMake(0, 0, 0, self.SwithchBtn1.titleLabel.frame.size.width+0.5*ten);
    
    self.SwithchBtn4.titleLabel.font=[UIFont systemFontOfSize:15];
    
    [self.SwithchBtn4 setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
    [self.SwithchBtn4 setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
    
    BOOL selectedtd= [WZHUserDefaults WZHBoolForKey:[NSString stringWithFormat:@"%@SwithchBtn4",self.title]];
    self.SwithchBtn4.selected=selectedtd;
    
    [view addSubview:self.SwithchBtn3];
    [view addSubview:self.SwithchBtn4];
    [view addSubview:self.leftLab2];
    [self.view addSubview:view];
    
    NSString *left2= [WZHUserDefaults WZHObjectForKey:[NSString stringWithFormat:@"%@left2",self.title]];
    
    if (left2) {
        
        self.leftLab2.text=left2;
        self.leftLab2.textColor=[UIColor blackColor];
    }else{
        
        self.leftLab2.text=@"是否接受过治疗";
        self.leftLab2.textColor=[UIColor lightGrayColor];
    }
    
    [self.leftLab2 mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.left.mas_offset(ten);
        make.centerY.mas_offset(0);
    }];
    
    [self.SwithchBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_offset(ten*1.2);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(10*ten);
        make.height.mas_equalTo(3*ten);
    }];
    
    [self.SwithchBtn4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_offset(self.view.frame.size.width*0.3);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(9*ten);
        make.height.mas_equalTo(3*ten);
    }];
}

//第五个view
-(void)loadBtnBaseView3:(UILabel *)label2 xMargin:(CGFloat)xMargin  i:(CGFloat)i btn:(UIButton *)btn1{
    
    btn1.backgroundColor=[UIColor whiteColor];
    
    //创建左边的label
    self.label3=[[UILabel alloc]init];
    self.label3.font=[UIFont systemFontOfSize:15];
    [btn1 addSubview:self.label3];
    
    //创建右边的线
    UIView *line=[[UIView alloc]init];
    [btn1 addSubview:line];
    line.backgroundColor=[[UIColor alloc]initWithWhite:0.5 alpha:0.5];
    [btn1 addTarget:self action:@selector(changeVC:) forControlEvents:UIControlEventTouchUpInside];
    
    //创建右边绿色箭头
    UIImageView *image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
    
    [btn1 addSubview:image];
    
    [self.view addSubview:btn1];
    
    //读取本地的数据
    NSString *str= [WZHUserDefaults WZHObjectForKey:[NSString stringWithFormat:@"%@labelStr3",self.title]];
    if (str) {
        
        self.label3.text=str;
        self.label3.textColor=[UIColor blackColor];
        
    }else{
        self.label3.text=@"请选择治疗方式";
        self.label3.textColor=[UIColor lightGrayColor];
    }
    
    //设置约束
    [self.label3 mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.left.mas_offset(ten);
        make.centerY.mas_offset(0);
    }];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_offset(-1.7*ten);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(0.8*ten);
        make.height.mas_equalTo(ten);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(image.mas_left).offset(-ten);
        make.centerY.mas_offset(0);
        make.width.mas_equalTo(ten/8);
        make.height.mas_equalTo(viewHeight/1.8);
    }];
    
    
}

//MARK:四个switch按钮的点击事件
-(void)click1:(UIButton *)btn{

    
    self.SwithchBtn1.selected=YES;
    self.SwithchBtn2.selected=!self.SwithchBtn1.selected;
    //数据存储在本地
    
    self.leftLab1.text=@"症状疑似";
    self.leftLab1.textColor=[UIColor blackColor];
}

-(void)click2:(UIButton *)btn{
    
    self.SwithchBtn2.selected=YES;
    self.SwithchBtn1.selected=!self.SwithchBtn2.selected;
    
    self.leftLab1.text=@"已确诊";
    self.leftLab1.textColor=[UIColor blackColor];
}

-(void)click3:(UIButton *)btn{
    
    self.SwithchBtn3.selected=YES;
    self.SwithchBtn4.selected=!self.SwithchBtn3.selected;
    
    if (btn.selected==NO) {
        
        self.btn3.hidden=NO;
    }else{
        
        self.btn3.hidden=YES;
    }
    
    self.leftLab2.text=@"未接受过";
    self.leftLab2.textColor=[UIColor blackColor];
    self.label3.text=@"请选择治疗方式";
    self.label3.textColor=[UIColor lightGrayColor];
}

-(void)click4:(UIButton *)btn{
    self.SwithchBtn4.selected=YES;
    self.SwithchBtn3.selected=!self.SwithchBtn4.selected;
    
    if (btn.selected==YES) {
        
        self.btn3.hidden=NO;
    }else{
        
        self.btn3.hidden=YES;
    }
    
    self.leftLab2.text=@"接受过";
    self.leftLab2.textColor=[UIColor blackColor];
    
}

//就医申请
-(void)clickApplyFor{
    
    FDAttentionController *atVC=[[FDAttentionController alloc]init];
    [self.navigationController pushViewController:atVC animated:YES];
}

//加载本地数据并进行赋值
-(void)getHomeDataAndSetData{
    
    //取出本地的字典数组
    NSString * docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES) lastObject];
    NSString * fileName = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@models",self.title]];
    NSArray * models = [NSArray arrayWithContentsOfFile:fileName];
    //将取出来的字典数组转化为模型数组
    NSMutableArray *arrayDict=[NSMutableArray array];
    for (int i=0; i<models.count; i++) {
        
        NSDictionary *dict=models[i];
        //字典转模型
        FDCellModel *cellModel=[FDCellModel modelWithDict:dict];
        [arrayDict addObject:cellModel];
    }
    
    //取出模型内部的点击过的数据
    NSMutableString *stringData=[NSMutableString string];
    
    for (FDCellModel *cellModel in arrayDict) {
        
        if (cellModel.isClick) {
            
            stringData=[NSMutableString stringWithFormat:@"%@、%@",stringData,cellModel.title];
        }
    }
    if (stringData.length) {
        
        stringData=(NSMutableString *)[stringData substringFromIndex:1];
    }
    
    if (stringData.length) {
        
        self.label2.text=stringData;
        self.label2.textColor=[UIColor blackColor];
    }else{
        self.label2.text=@"请选择并发症（可多选）";
        self.label2.textColor=[UIColor lightGrayColor];
    }
}



-(void)changeVC:(UIButton *)btn{
    
    //当为并发症按钮
    if (btn.tag==2) {
        
        FDTableVIewVC *VC=[[FDTableVIewVC alloc]init];
        
        __weak typeof (self) weakSelf=self;
        [VC cellback:^(NSArray *arrString) {
            
            //遍历一下模型数组
            NSMutableString *string=[[NSMutableString alloc]init];
            //记录红色的个数
            int num=0;
            for (FDCellModel *model in arrString) {
                
                //判断模型里面的状态，如果是红色就输出
                if (model.isClick) {
                    
                    string=[NSMutableString stringWithFormat:@"%@、%@",string,model.title];
                    num++;
                }
            }
            //如果并发症没有选择，则显示原始数据
            if (num==0) {
                
                weakSelf.label2.text=@"请选择并发症（可多选）";
                weakSelf.label2.textColor=[UIColor lightGrayColor];
                return;
            }
            
            //此处截取顿号
            string = (NSMutableString *)[string substringFromIndex:1];
            weakSelf.label2.text=string;
            weakSelf.label2.textColor=[UIColor blackColor];
            
            //数据存储在本地
            [WZHUserDefaults WZHSaveObject:string forKey:[NSString stringWithFormat:@"%@bingfazheng",self.title]];
            
            //将模型数组转化为字典数组
            NSMutableArray *arrayl=[NSMutableArray array];
            for (int i=0; i<arrString.count; i++) {
                
                FDCellModel *cellModel=arrString[i];
                NSDictionary *dict=cellModel.keyValues;
                [arrayl addObject:dict];
            }
            
            //保存数组在本地
            NSString * docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES) lastObject];
            
            NSString * fileName = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@models",self.title]];
            
            [arrayl writeToFile:fileName atomically:YES];
        }];
        
        [self.navigationController pushViewController:VC animated:YES];
    }
    
    //当为疾病细分按钮
    if (btn.tag==1) {
        
        FDDiseaseSubdivideViewController *disVC=[[FDDiseaseSubdivideViewController alloc]init];
        
        [disVC returnText:^(NSString *showText) {
            self.label1.text = showText;
            
            //存储本地数据
            [WZHUserDefaults WZHSaveObject:showText forKey:[NSString stringWithFormat:@"%@showText",self.title]];
            self.label1.textColor = [UIColor blackColor];
        }];
        
        [self.navigationController pushViewController:disVC animated:YES];
    }
    
    //治疗方式按钮
    if (btn.tag==3) {
        
        FDOperationVC *disVC=[[FDOperationVC alloc]init];
        
        [self.navigationController pushViewController:disVC animated:YES];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc{
    
    //数据存储在本地
    [WZHUserDefaults WZHSaveBoolValue:self.SwithchBtn3.selected forKey:[NSString stringWithFormat:@"%@SwithchBtn3",self.title]];
    [WZHUserDefaults WZHSaveBoolValue:self.SwithchBtn4.selected forKey:[NSString stringWithFormat:@"%@SwithchBtn4",self.title]];
    [WZHUserDefaults WZHSaveBoolValue:self.SwithchBtn2.selected forKey:[NSString stringWithFormat:@"%@SwithchBtn2",self.title]];
    [WZHUserDefaults WZHSaveBoolValue:self.SwithchBtn1.selected forKey:[NSString stringWithFormat:@"%@SwithchBtn1",self.title]];
    
    [WZHUserDefaults WZHSaveObject:self.leftLab1.text forKey:[NSString stringWithFormat:@"%@left1",self.title]];
    [WZHUserDefaults WZHSaveObject:self.leftLab2.text forKey:[NSString stringWithFormat:@"%@left2",self.title]];
    
    if (self.SwithchBtn3.selected==YES) {
        
        [WZHUserDefaults WZHSaveObject:nil forKey:[NSString stringWithFormat:@"%@labelStr3",self.title]];
    }
    
//    if (self.SwithchBtn4.selected==YES) {
//        
//        [WZHUserDefaults WZHSaveObject:nil forKey:@"labelStr3"];
//    }
    
}

@end
